package com.emar.adx.yiqifa.util;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;

import java.io.IOException;
import java.util.Properties;

/**
 * Created by Administrator on 2015/11/21 0021.
 */
public class Configuration {

    private static final Log log = LogFactory.getLog(Configuration.class);

    private Properties properties = null;

    private String fileName = "";

    public Configuration(String fileName) {
        this.fileName = fileName;
        if(properties==null){
            Resource resource = new ClassPathResource(fileName);
            try {
                this.properties = PropertiesLoaderUtils.loadProperties(resource);
            }catch (IOException e){
                log.error("property file not found ",e);
            }
        }
    }

    public String getString(String p){
        return properties.getProperty(p);
    }

    public int getInt(String p){
        return FunctionUtil.parseInt(properties.getProperty(p),0);
    }


    public long getLong(String p){
        return FunctionUtil.parseLong(properties.getProperty(p),0);
    }
}
